USE [aspnetdb]
GO

-- =============================================
-- Author     :		Lohith Ram D V
-- Create date:         08/mar/2011
-- Description:	Tells the database to record a document is checked out.  Also checks for that right.  
--                Returns 1 if happens, 0 otherwise.
-- =============================================

create procedure sp_DocumentCheckIn (
	@par_userid int,
	@par_docid int)
AS
BEGIN
	DECLARE @user_role int
	DECLARE @user_right int
	
	SELECT @user_role = (SELECT ([role_id])
	FROM [User1]
	WHERE @par_userid = [User1].[user1_id]);
	
	SELECT @user_right = (SELECT ([right1_id])
	FROM [Role_Right]
	WHERE @user_role=[Role_Right].[role_id]);
	
	if(@user_right = 6)
		BEGIN
			DELETE FROM [Doc_Checked]
			WHERE @par_docid=[Doc_Checked].[doc_id] AND @par_userid=[Doc_Checked].[user1_id];
			RETURN 1;
		END
		ELSE
		BEGIN
			return 0;
		END
END


